home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / FWFont.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  6.8 KB  |  243 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFont.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWFONT_H
  13. #include "FWFont.h"
  14. #endif
  15.  
  16. #ifndef FWGC_H
  17. #include "FWGC.h"
  18. #endif
  19.  
  20. #ifndef FWPOINT_H
  21. #include "FWPoint.h"
  22. #endif
  23.  
  24. #ifndef FWFXMATH_H
  25. #include "FWFxMath.h"
  26. #endif
  27.  
  28. #ifndef FWGRUTIL_H
  29. #include "FWGrUtil.h"
  30. #endif
  31.  
  32. #ifndef FWSTRMRW_H
  33. #include "FWStrmRW.h"
  34. #endif
  35.  
  36. // ----- Macintosh Includes -----
  37.  
  38. #if defined(FW_BUILD_MAC) && !defined(__TEXTUTILS__)
  39. #include <TextUtils.h>
  40. #endif
  41.  
  42. #if defined(FW_BUILD_MAC) && !defined(__FONTS__)
  43. #include <Fonts.h>
  44. #endif
  45.  
  46. #ifdef FW_BUILD_MAC
  47. #pragma segment FWGraphics_Font
  48. #endif
  49.  
  50. //========================================================================================
  51. //    Template instantiation
  52. //========================================================================================
  53.  
  54. #include "FWGrRef.tpp"
  55.  
  56. FW_DEFINE_AUTO_TEMPLATE(FW_TGrRefPtr, FW_HFont)
  57.  
  58. #ifdef FW_USE_TEMPLATE_PRAGMAS
  59.  
  60. #pragma template_access public
  61. #pragma template FW_TGrRefPtr<FW_HFont>
  62.  
  63. #else
  64.  
  65. template class FW_TGrRefPtr<FW_HFont>;
  66.  
  67. #endif
  68.  
  69. //========================================================================================
  70. //    class FW_CFont
  71. //========================================================================================
  72.  
  73. FW_DEFINE_AUTO(FW_CFont)
  74.  
  75. //----------------------------------------------------------------------------------------
  76. //    FW_PrivAcquireGrRep
  77. //----------------------------------------------------------------------------------------
  78.  
  79. void FW_PrivAcquireGrRep(FW_HFont rep)
  80. {
  81.     if (rep != 0)
  82.         FW_PrivFont_Acquire(rep);
  83. }
  84.  
  85. //----------------------------------------------------------------------------------------
  86. //    FW_PrivReleaseGrRep
  87. //----------------------------------------------------------------------------------------
  88.  
  89. void FW_PrivReleaseGrRep(FW_HFont rep)
  90. {
  91.     if (rep != 0)
  92.         FW_PrivFont_Release(rep);
  93. }
  94.  
  95. //----------------------------------------------------------------------------------------
  96. //    FW_CFont::FW_CFont
  97. //----------------------------------------------------------------------------------------
  98.  
  99. FW_CFont::FW_CFont(const FW_CString& fontName, FW_FontStyle fontStyle, FW_Fixed fontSize)
  100. {
  101.     FW_PlatformError error;
  102.     FW_HFont rep = FW_PrivFont_Create(fontName, fontStyle, fontSize, &error);
  103.     FW_FailOnError(error);
  104.     SetRep(rep);
  105.     FW_END_CONSTRUCTOR
  106. }
  107.  
  108. //----------------------------------------------------------------------------------------
  109. //    FW_CFont::FW_CFont
  110. //----------------------------------------------------------------------------------------
  111.  
  112. FW_CFont::FW_CFont(const FW_CFont& other) :
  113.     FW_TGrRefPtr<FW_HFont>(other)
  114. {
  115.     FW_END_CONSTRUCTOR
  116. }
  117.  
  118. //----------------------------------------------------------------------------------------
  119. //    FW_CFont::FW_CFont
  120. //----------------------------------------------------------------------------------------
  121.  
  122. FW_CFont::FW_CFont(FW_EStandardFonts std)
  123. {
  124.     FW_PlatformError error;
  125.     FW_HFont rep = FW_PrivFont_CreateStandard(std, &error);
  126.     FW_FailOnError(error);
  127.     SetRep(rep);
  128.     FW_END_CONSTRUCTOR
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    FW_CFont::FW_CFont
  133. //----------------------------------------------------------------------------------------
  134.  
  135. FW_CFont::~FW_CFont()
  136. {
  137.     FW_START_DESTRUCTOR
  138. }
  139.  
  140. //----------------------------------------------------------------------------------------
  141. //    FW_CFont::operator=
  142. //----------------------------------------------------------------------------------------
  143.  
  144. FW_CFont& FW_CFont::operator=(const FW_CFont& other)
  145. {
  146.     FW_TGrRefPtr<FW_HFont>::operator=(other);
  147.     return *this;
  148. }
  149.  
  150. //----------------------------------------------------------------------------------------
  151. //    FW_CFont::operator=
  152. //----------------------------------------------------------------------------------------
  153.  
  154. FW_CFont& FW_CFont::operator=(FW_EStandardFonts std)
  155. {
  156.     FW_PlatformError error;
  157.     FW_HFont rep = FW_PrivFont_CreateStandard(std, &error);
  158.     FW_FailOnError(error);
  159.     SetRep(rep);
  160.     return *this;
  161. }
  162.  
  163. //----------------------------------------------------------------------------------------
  164. //    FW_CFont::GetFontName
  165. //----------------------------------------------------------------------------------------
  166.  
  167. void FW_CFont::GetFontName(FW_CString& fontName) const
  168. {
  169.     FW_PlatformError error;
  170.     FW_PrivFont_GetName(fRep, fontName, &error);
  171.     FW_FailOnError(error);
  172. }
  173.  
  174. //----------------------------------------------------------------------------------------
  175. //    FW_CFont::SetFontName
  176. //----------------------------------------------------------------------------------------
  177.  
  178. void FW_CFont::SetFontName(const FW_CString& fontName)
  179. {
  180.     FW_PlatformError error;
  181.     FW_PrivFont_SetName(fRep, fontName, &error);
  182.     FW_FailOnError(error);
  183. }
  184.  
  185. //----------------------------------------------------------------------------------------
  186. //    FW_CFont::GetFontMetrics
  187. //----------------------------------------------------------------------------------------
  188.  
  189. void FW_CFont::GetFontMetrics(FW_HGDevice device, FW_CFontMetrics& fontMetrics) const
  190. {    
  191.     FW_FailOnError(FW_PrivGDev_GetFontMetrics(device, *this, fontMetrics));
  192. }
  193.  
  194. //----------------------------------------------------------------------------------------
  195. //    FW_CFont::GetFontMetrics
  196. //----------------------------------------------------------------------------------------
  197.  
  198. void FW_CFont::GetFontMetrics(FW_CGraphicContext& gc, FW_CFontMetrics& fontMetrics) const
  199. {
  200.     GetFontMetrics(gc.GetGraphicDevice(), fontMetrics);
  201. }
  202.  
  203. //----------------------------------------------------------------------------------------
  204. //    FW_CFont::Copy
  205. //----------------------------------------------------------------------------------------
  206.  
  207. FW_CFont FW_CFont::Copy() const
  208. {
  209.     FW_PlatformError error;
  210.     FW_HFont rep = FW_PrivFont_Copy(fRep, &error);
  211.     FW_FailOnError(error);
  212.     
  213.     FW_CFont font;
  214.     font.SetRep(rep);
  215.     return font;
  216. }
  217.  
  218. //----------------------------------------------------------------------------------------
  219. //    operator <<
  220. //----------------------------------------------------------------------------------------
  221.  
  222. FW_CWritableStream& operator << (FW_CWritableStream& stream, const FW_CFont& font)
  223. {
  224.     FW_PlatformError error;
  225.     FW_PrivFont_Write(font.fRep, stream, &error);
  226.     FW_FailOnError(error);
  227.     return stream;
  228. }
  229.  
  230. //----------------------------------------------------------------------------------------
  231. //    operator >>
  232. //----------------------------------------------------------------------------------------
  233.  
  234. FW_CReadableStream& operator >> (FW_CReadableStream& stream, FW_CFont& font)
  235. {
  236.     FW_PlatformError error;
  237.     FW_HFont rep = FW_PrivFont_Read(stream, &error);
  238.     FW_FailOnError(error);
  239.     font.SetRep(rep);
  240.     return stream;
  241. }
  242.  
  243.